home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / ARCNET.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-23  |  2.5 KB  |  124 lines

  1. /* Stuff generic to all ARCnet controllers
  2.  * Copyright 1990 Russ Nelson
  3.  */
  4. #ifdef MSDOS
  5. #include "global.h"
  6. #ifdef ARCNET
  7. #include "mbuf.h"
  8. #include "iface.h"
  9. #include "arp.h"
  10. #include "arcnet.h"
  11.  
  12. #if !defined(_lint)
  13. static char rcsid[] OPTIONAL = "$Id: arcnet.c,v 1.6 1996/12/23 20:37:36 root Exp root $";
  14. #endif
  15.  
  16. uint8 ARC_bdcst[] = { 0 };
  17.  
  18. /* Convert ARCnet header in host form to network mbuf */
  19. void
  20. htonarc(
  21. struct arc *arc,
  22. struct mbuf **bpp
  23. ){
  24.     uint8 *cp;
  25.  
  26.     (void) pushdown(*bpp,ARCLEN);
  27.  
  28.     cp = (*bpp)->data;
  29.  
  30.     memcpy(cp,arc->source,AADDR_LEN);
  31.     cp += AADDR_LEN;
  32.     memcpy(cp,arc->dest,AADDR_LEN);
  33.     cp += AADDR_LEN;
  34.     *cp++ = arc->type;
  35. }
  36. /* Extract ARCnet header */
  37. int
  38. ntoharc(arc,bpp)
  39. struct arc *arc;
  40. struct mbuf **bpp;
  41. {
  42.     (void) pullup(bpp,arc->source,AADDR_LEN);
  43.     (void) pullup(bpp,arc->dest,AADDR_LEN);
  44.     arc->type = uchar(PULLCHAR(bpp));
  45.     return ARCLEN;
  46. }
  47.  
  48. /* Format an ARCnet address into a printable ascii string */
  49. char *
  50. parc(out,addr)
  51. char *out;
  52. uint8 *addr;
  53. {
  54.     sprintf(out,"%02x", addr[0]);
  55.     return  out;
  56. }
  57.  
  58. /* Convert an ARCnet address from Hex/ASCII to binary */
  59. int
  60. garc(out,cp)
  61. uint8 *out;
  62. const char *cp;
  63. {
  64.     *out = (uint8) htoi(cp);
  65.     return 0;
  66. }
  67. /* Send an IP datagram on ARCnet */
  68. int
  69. anet_send(
  70. struct mbuf **bpp,    /* Buffer to send */
  71. struct iface *iface,    /* Pointer to interface control block */
  72. uint32 gateway,        /* IP address of next hop */
  73. uint8 tos
  74. ){
  75.     char *agate;
  76.  
  77.     agate = res_arp(iface,ARP_ARCNET,gateway,*bpp);
  78.     if(agate != NULL)
  79.         return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,*bpp);
  80.     return 0;
  81. }
  82. /* Send a packet with ARCnet header */
  83. int
  84. anet_output(
  85. struct iface *iface,    /* Pointer to interface control block */
  86. uint8 *dest,        /* Destination ARCnet address */
  87. uint8 *source,        /* Source ARCnet address */
  88. uint type,        /* Type field */
  89. struct mbuf **data    /* Data field */
  90. ){
  91.     struct arc ap;
  92.  
  93.     memcpy(ap.dest,dest,AADDR_LEN);
  94.     memcpy(ap.source,source,AADDR_LEN);
  95.     ap.type = uchar(type);
  96.     htonarc(&ap,data);
  97.     return (*iface->raw)(iface,*data);
  98. }
  99. /* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
  100. void
  101. aproc(
  102. struct iface *iface,
  103. struct mbuf *bp
  104. ){
  105.     struct arc hdr;
  106.  
  107.     /* Remove ARCnet header and kick packet upstairs */
  108.     (void) ntoharc(&hdr,&bp);
  109.     switch(hdr.type){
  110.     case ARC_ARP:
  111.         arp_input(iface,bp);
  112.         break;
  113.     case ARC_IP:
  114.         (void) ip_route(iface,bp,0);
  115.         break;
  116.     default:
  117.         free_p(bp);
  118.         break;
  119.     }
  120. }
  121.  
  122. #endif        /* ARCNET */
  123. #endif        /* MSDOS */
  124.